-
Notifications
You must be signed in to change notification settings - Fork 378
fix: reduce API test memory consumption from 8.26GB to 1.57GB (#8263) #9097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: reduce API test memory consumption from 8.26GB to 1.57GB (#8263) #9097
Conversation
…rse#8263) Addresses excessive memory usage in API tests that consumed >40GB virtual memory and >6GB resident memory, causing slower test execution. Root cause: Tests inherited production cache configurations (1GB local cache, 400MB SSTable cache) and ristretto's fixed 10M counter allocation created massive overhead for small test caches. Changes: - Set test-specific cache sizes (8MB local, 2MB SSTable) in serve_test.go - Scale ristretto counters adaptively based on cache capacity in eviction.go - Maintain full test functionality while reducing memory footprint by 81% Before: 8.26GB total allocation (6.7GB from ristretto caches) After: 1.57GB total allocation (50MB from ristretto caches) Tests: All controller tests pass with identical functionality
Does this fix #8263? 🕺🏽 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving to @nopcoder to review properly. Just preferences about one of the default values - which you should both feel free to ignore.
Overall this is really cool and exciting - looking forward to a faster api.test!!1!
@@ -113,6 +113,11 @@ func setupHandler(t testing.TB) (http.Handler, *dependencies) { | |||
// Add endpoint so that 'IsAdvancedAuth' will be in effect | |||
viper.Set("auth.api.endpoint", config.DefaultListenAddress) | |||
|
|||
// Set minimal cache sizes for testing to reduce memory consumption | |||
// Default production values are too large for test environments | |||
viper.Set("committed.local_cache.size_bytes", 8*1024*1024) // 8MB instead of 1GB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
viper.Set("committed.local_cache.size_bytes", 8*1024*1024) // 8MB instead of 1GB | |
viper.Set("committed.local_cache.size_bytes", 24*1024*1024) |
- Remove the comment - keeping it means we need to keep this file sync'ed up with defaults.go, and we won't do that.
- We'll anyway probably never hit this in a small test, but if we do - it will slow down the API test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you contribution! I like to merge this change, can you address ariel's comment (removing the comment about the default) and we'll merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good - thanks, left a comment related to the lint errors.
numCountersToUse = capacity / (1024 * 10) // ~100 counters per 10KB | ||
if numCountersToUse < 1000 { | ||
numCountersToUse = 1000 // Minimum threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set constants for the numbers with meaningful names, our lint rules don't like magic numbers.
Memory Optimization Fix for API Tests - Issue #8263
API tests were consuming excessive memory (>40 GiB virtual, >6 GiB resident), causing slower test execution and reduced developer adoption.
RCA
Memory Profile Findings (Before Optimization)
ristretto.newCmRow
: 4.5 GB (54.42%)ristretto.Bloom.Size
: 2.2 GB (27.21%)Root Cause
Default Production Configuration in Tests: Tests were using production-level cache sizes:
committed.local_cache.size_bytes
: 1 GB (default)committed.sstable.memory.cache_size_bytes
: 400 MB (default)Ristretto Cache Overhead: The ristretto cache allocates 10 million counters regardless of actual cache capacity, creating massive memory overhead for test environments.
Multiple Cache Instances: Each test creates two pyramid filesystem caches:
Test Repetition: 50+ controller tests each calling
setupHandler()
with fresh cache instances.Results
Memory Allocation Improvement
Ristretto Cache Impact
Testing
Verification
Fixes #8263